<?php
	class schoolordermodel extends Model {
		function schoolordermodel()
		{
			parent::Model();			
		}
		
		function add($data)
		{
			$this->db->insert('school_order', $data);
			return $this->db->insert_id();
		}
		
		function update($data)
		{
			if(isset($data['school_name']))
				$dataDB['school_name'] = $data['school_name'];
			if(isset($data['seq']))
				$dataDB['seq'] = $data['seq'];
            $this->db->where('order_id', $data['order_id']);
			$this->db->update('school_order', $dataDB); 
		}
		
		function getMaxSeq()
		{
			$this->db->select_max('seq');
			$query = $this->db->get('school_order');
			$data = $query->row_array();
			if($data['seq'] == null)
				return 1;
				
			return $data['seq']+1;
		}
		
		function updateSeq($id, $seq, $nn)
		{			
			$data = array(
               'seq' => $seq,
				'school_name' => $nn
			
            );
            $this->db->where('order_id', $id);
			$this->db->update('school_order', $data); 
		}
		
		function getByID($id)
		{
			$query = $this->db->get_where('school_order', array('order_id' => $id));
			return $query->row_array();
		}
		
		function getAll()
		{
			$this->db->order_by("seq", "asc"); 
			$query = $this->db->get('school_order');
			return $query->result();
		}
		
		function delete($data)
		{	
			$this->db->where('order_id', $data);
			$this->db->delete('school_order');
		}		
	
	}
?>